package com.cloudptt.wp.ui.more.advanced;

import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.res.Resources;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.preference.SwitchPreference;

import com.cloudptt.api.product.log.Log;
import com.cloudptt.wp.R;
import com.cloudptt.wp.ui.BasePreferenceActivity;

public class VoiceSettingActivity extends BasePreferenceActivity
		implements OnPreferenceChangeListener, OnPreferenceClickListener, OnSharedPreferenceChangeListener {

	public static final String THIS_FILE = "VoiceSettingActivity";
	
	private SwitchPreference privateSpeakerEnableSwitch = null;
	private SwitchPreference gsmCallFirstSwitch = null;
//	private CallConfig config = null;
	
	SharedPreferences sp;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.prefs_voice);
		
		this.sp = PreferenceManager.getDefaultSharedPreferences(VoiceSettingActivity.this);
		this.sp.registerOnSharedPreferenceChangeListener(this);
		
		initSummary();
	}
	
	private void initSummary()
	{
		Resources res = this.getResources();
		String key = res.getString(R.string.answer_mode_voice);
		privateSpeakerEnableSwitch = (SwitchPreference)getPreferenceScreen().findPreference(key); 
		boolean value = sp.getBoolean(key, true);
		privateSpeakerEnableSwitch.setChecked(value);
		
		key = res.getString(R.string.answer_mode_video);
		gsmCallFirstSwitch = (SwitchPreference)getPreferenceScreen().findPreference(key); 
		value = sp.getBoolean(key, false);
		gsmCallFirstSwitch.setChecked(value);
	}

	@Override
	public boolean onPreferenceChange(Preference preference, Object newValue) {
		Log.i(THIS_FILE, "onPreferenceChange:newValue="+newValue);
		return true;
	}

	@Override
	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
		Log.i(THIS_FILE, "onSharedPreferenceChanged:key= " + key );
		if(key == null
				|| key.length() <= 0)
		{
			return;
		}
		
		initSummary();
//		String pCallSpeakOnKey = this.getString(R.string.pref_voice_private_speaker_enable);
//		String gsmOnKey = this.getString(R.string.pref_voice_gsm_call_priority_enable);
//		if(key.equals(pCallSpeakOnKey))
//		{
//			config.setConfig(gsmOnKey, val)//.setGsmFirst(isGsmFirst)
//		}
//		else if(key.equals(gsmOnKey))
//		{
//			
//		}
	}

	@Override
	public boolean onPreferenceClick(Preference preference) {
		Log.i(THIS_FILE, "onPreferenceClick");
		return false;
	}
	
	@Override
	public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
		Log.i(THIS_FILE, "onPreferenceTreeClick");
		
		return false;
	}
}
